package glassline;

import glassline.interfaces.Popup;
import transducer.Transducer;
import agent.*;

public class PopupAgent extends Agent implements Popup {
	public PopupState state = PopupState.Down;
	public Glass currentGlass = null;

	public PopupAgent(Transducer t) {
		super(t);
	}
	
	// Messages
	
	/* (non-Javadoc)
	 * @see glassline.Popup#msgHereIsGlass(glassline.Glass)
	 */
	public void msgHereIsGlass(Glass g) { // Message from previous factory component
		currentGlass = g;
		stateChanged();
	}

	/* (non-Javadoc)
	 * @see glassline.Popup#msgPopUp()
	 */
	@Override
	public void msgPopUp() { // Message from conveyor
		state = PopupState.MovingUp;
		stateChanged();
	}

	/* (non-Javadoc)
	 * @see glassline.Popup#msgPopDown()
	 */
	@Override
	public void msgPopDown() { // Message from conveyor
		state = PopupState.MovingDown;
		stateChanged();
	}

	/* (non-Javadoc)
	 * @see glassline.Popup#pickAndExecuteAnAction()
	 */
	@Override
	public boolean pickAndExecuteAnAction() {
		if (state == PopupState.MovingUp) {
			state = PopupState.Up;
			return true;
		}
		else if (state == PopupState.MovingDown) {
			state = PopupState.Down;
			return true;
		}
		
		return false;
	}

	// Actions
	
	// Unit testing stufff
	/* (non-Javadoc)
	 * @see glassline.Popup#printData()
	 */
	@Override
	public void printData() {
		System.out.println("State: " + state);
		System.out.println("current glass: " + currentGlass);
	}
}
